<?php
$routerBase = lcfirst(self::$console->className) ;
?>
<?php echo '<?php'?>

namespace backend\controllers<?=$subControllerNameSpace?>;
Use <?=self::$console->model?>;
use backend\controllers\BackendBase;
use yii\helpers\Json;

class <?=$trueClassName?>Controller extends BackendBase
{
    public function actionIndex(){
        if(!$this->isJson){
            return $this->renderView('/<?=self::$console->view?>/index');
        }
        return $this->page( <?=$trueModelName?>::find() ) ;
    }


    public function actionSave(){
        $id = $this->request()->get('id',0);
        if(!$this->isPost){

            $data = '""' ;
            if($id){
                $model = <?=$trueModelName?>::findOne($id);
                $data = Json::encode($model) ;
            }

            return $this->renderView('/<?=self::$console->view?>/save',['data' => $data]);
        }

        $data = $this->request()->post() ;

        if($id){
            $model = <?=$trueModelName?>::findOne($id);
        }else{
            $model = new <?=$trueModelName?>();
        }


        if($model->load($data,'') && $model->save()){
            return true ;
        }else{
            return $model->getErrors() ;
        }
    }


    public function actionDelete(){
        $id = $this->request()->get('id',0);
        $isDelete = <?=$trueModelName?>::findOne($id)->delete();
        return ['code' => 0];
    }
}